home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Files / XTND 1.3.6 / Translator Examples / PICT Translator / PICTImport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-23  |  2.2 KB  |  71 lines  |  [TEXT/MPS ]

  1. /************************************************************************
  2. *                                                                        *
  3. *    PICTImport.c                                                        *
  4. *                                                                        *
  5. *    Translator for reading a PICT file with XTND 1.3.                      *
  6. *                                                                        *
  7. *    Copyright © 1988 Claris Corporation                                    *
  8. *    All Rights Reserved                                                    *
  9. *                                                                        *
  10. *    Author: Michael Hilton                                                *
  11. *    Date:   15 July, 1988                                                *
  12. *                                                                        *
  13. ************************************************************************/
  14.  
  15. #include <QuickDraw.h>
  16. #include <StandardFile.h>
  17. #include <Memory.h>
  18. #include <Errors.h>
  19.  
  20. #include ":::XTND Headers:XTNDCIncludes:XTNDPictTranslator.h"
  21.  
  22. /*------------------------- Useful Constants ---------------------------*/
  23.  
  24. #define PICTHEADERSIZE    512
  25.  
  26.  
  27. /*-------------------------Function prototypes--------------------------*/
  28.  
  29. void    main(PictImportParmBlkPtr);
  30.  
  31.  
  32. /*----------------------------------------------------------------------*/
  33. /*    main    This is the main routine of the translator.                    */
  34. /*----------------------------------------------------------------------*/
  35. void main(register PictImportParmBlkPtr ourPtr)
  36. {
  37.     register long    savePictSize;
  38.     register Handle    thePicture;
  39.     long            pictSize; 
  40.     
  41.     ourPtr->result = noErr;
  42.     
  43.     if (ourPtr->directive != importGetPict)    /* Check for a valid directive */
  44.         return;
  45.     
  46.     /* Determine the size of the picture (= size of the file - 512) */
  47.     GetEOF(ourPtr->dataRefNum, &pictSize);    /* Get the size of the file */
  48.     pictSize -= PICTHEADERSIZE;                /* Subtract the size of the header */
  49.     savePictSize = pictSize;                /* Save it for later */
  50.  
  51.     thePicture = NewHandle(pictSize);        /* Create the picture handle */
  52.     if (ourPtr->result = MemError())
  53.         return;
  54.     
  55.     /* skip over the header information */
  56.     if (ourPtr->result = SetFPos(ourPtr->dataRefNum, fsFromStart, PICTHEADERSIZE))
  57.         return;
  58.     
  59.     HLock(thePicture);                        /* Read the picture into memory */
  60.     if (ourPtr->result = FSRead(ourPtr->dataRefNum, &pictSize, *thePicture)) return;
  61.     HUnlock(thePicture);
  62.  
  63.     if (savePictSize == pictSize) {            /* If we have successfully read in a picture */        
  64.         ourPtr->thePicture = (PicHandle)thePicture;
  65.     } else {                                /* We have not read all of the picture */
  66.         DisposHandle(thePicture);
  67.         ourPtr->result = ioErr;                /* Return an error */
  68.     }
  69. }
  70.  
  71.